package web.modalWindow;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;

public class ModalWindowHome extends WebPage{
	private static final long serialVersionUID = 1L;
	private ModalWindow ventana;
	
	
	public ModalWindowHome() {
		Form<Void> form = new Form<Void>("form");
		add(
			form.add(boton()),
			modalWindow()
		);
	}

	private Component modalWindow() {
		ventana = new ModalWindowPersonalizada("ventana");
		ventana.setTitle("Ejemplo ModalWindow");
		return ventana;
	}

	private Component boton() {
		return new AjaxButton("boton") {
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				ventana.setContent(new ContenidoVentana(ventana.getContentId()));
				ventana.show(target);
			}
			
			@Override
			protected void onError(AjaxRequestTarget target, Form<?> form) {}
		};
	}
}